package com.dp;

public class Solution34 {
    public int maxProfit(int[] prices) {
        if (prices.length==1) return 0;
        int dpi0 = -prices[0];
        int dpi1 = 0;
        int tmp = dpi0;
        for (int i = 1; i < prices.length; i++) {
            dpi0 = Math.max(dpi0,dpi1-prices[i]);
            dpi1 = Math.max(dpi1,prices[i]+tmp);
            tmp = dpi0;
        }
        return dpi1;
    }
}
